﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml.Linq;
using Kimgwajang.MidnightPeach.Properties;
using Kimgwajang.MidnightPeach.Schema;

namespace Kimgwajang.MidnightPeach.Forms
{
    public partial class DbmlWarningForm : Form
    {
        private readonly string _dbmlPath;

        private readonly List<XElement> _unupdatables;

        public DbmlWarningForm()
        {
            InitializeComponent();
        }

        public DbmlWarningForm(string dbmlPath, List<XElement> unupdatables) : this()
        {
            _dbmlPath = dbmlPath;
            _unupdatables = unupdatables;
        }

        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            _unupdatables.ForEach(x => lsbTable.Items.Add(x.Attribute("Name").Value));
        }

        private void btnYes_Click(object sender, EventArgs e)
        {
            bool added = SchemaExtractor.AddUpdateCheckAttribute(_dbmlPath);

            if (added)
                DialogResult = DialogResult.OK;
            else
                MessageBox.Show(Resources.CannotSaveDbmlFile);

            Close();
        }

        private void btnNo_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}